-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow importing package.json #2468
Conversation
It it a safe practice to do so? |
@rogovdm, I guess it depends what kind of date is in the Maybe it's better to only include the version property from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. descriptionFileRoot
is package.json
even if I import ../lol.json
. And it lets me do that. So this is probably the wrong thing to look at.
I assume that the correct thing to look at would be requestRelative
calculated below, and if it's equal exactly to ../package
or ../package.json
(since we can't use Webpack resolving mechanism yet).
const requestRelativeToRoot = path.relative( | ||
request.descriptionFileRoot, | ||
requestFullPath | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaearon you are totally right. My previous code wasn't working . I'm not sure what I did there, but this is what I meant to do - to check this is the package.json that's in the root. I didn't want to assume package.json always lives in ../src
in case the src is more than one level deep like true/src
I don't understand newly pushed commits. I was referring to using existing variable (which has the right thing). You renamed an old variable but it still calculates the wrong thing. |
I think it's OK, but maybe I'm missing something I wanted to check this is the package.json that resides in root: const requestRelativeToRoot = path.relative(
request.descriptionFileRoot,
requestFullPath
); |
I'm not sure myself. Just make sure importing |
now when I run it:
and |
Wouldn't it be easier to simply use this variable and add: if (requestRelative === `..${path.sep}package.json`) {
return callback();
} I might be missing something obvious. I have not tested this. |
@Timer I wanted it to check from the root and not |
Good point, @iamdoron. if (/^(..[/|\\])+package.json$/.test(requestRelative)) {
return callback();
} |
9be52d8
to
be60e23
Compare
); | ||
const requestRelative = path.relative(appSrc, requestFullPath); | ||
if (/^(..[/|\\])+package(.json)?$/.test(requestRelative)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Timer I changed it to regex, I added '?' in (.json)?
to make it optional. that way you can require("../package")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should always include the extension no matter what.
How about adding excludes option to ModuleScopePlugin?
|
@viankakrisna that's probably best long-term; what do you think @iamdoron? |
What's the status on this? What are requested changes? |
We should strictly enforce the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
@@ -13,8 +13,9 @@ const chalk = require('chalk'); | |||
const path = require('path'); | |||
|
|||
class ModuleScopePlugin { | |||
constructor(appSrc) { | |||
constructor(appSrc, allowedPaths = []) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit, how about allowedFiles
? Paths makes it sound like you can give it a directory.
packages/react-dev-utils/README.md
Outdated
@@ -57,7 +57,7 @@ module.exports = { | |||
``` | |||
|
|||
|
|||
#### `new ModuleScopePlugin(appSrc: string)` | |||
#### `new ModuleScopePlugin(appSrc: string, allowedPaths: [string])` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, allowedFiles
. And we should probably let them know it's optional allowedFiles?: string[]
.
What's the status on this? |
@br0p0p waiting for CI to pass, now. 😄 thanks for the ping! |
Thanks for this, @iamdoron! |
Hi there! This change is out in |
* Allow importing package.json * Remove package.json import from App.js template * fix importing package.json * Rename variable to reflect path is relative to root * Check for both package & package.json in ModuleScopePlugin * Use regex to check relative path to package.json * Strictly enforce package.json extension on scope plugin * Add allowedPaths to ModuleScopePlugin ctor and use it to allow app package.json * Remove package.json import from App.js template * Add package.json to react-scripts/template, show package version and name in the template * Remove import package.json from template * Remove template/package.json and its references in code * Update ModuleScopePlugin.js * Update README.md
* commit 'bfaee410c502a95076a6bd89721c76ca08e15f7b': (39 commits) Publish Prepare for 1.0.11 release (facebook#2924) Update dev deps (facebook#2923) Update README.md Use env variable to disable source maps (facebook#2818) Make formatWebpackMessages return all messages (facebook#2834) Adjust the `checkIfOnline` check if in a corporate proxy environment (facebook#2884) Fix the order of arguments in spawned child proc (facebook#2913) Feature/webpack 3 4 (facebook#2875) Allow importing package.json (facebook#2468) Re-enable flowtype warning (facebook#2718) Format UglifyJs error (facebook#2650) Unstage yarn.lock pre-commit (facebook#2700) Update README.md Update README.md Add Electrode to alternatives (facebook#2728) Fix parsing HTML/JSX tags to real elements (facebook#2796) Update webpack version note (facebook#2798) Use modern syntax feature (facebook#2873) Allow use of scoped packages with a pinned version (facebook#2853) ... # Conflicts: # packages/react-scripts/config/webpack.config.dev.js # packages/react-scripts/config/webpack.config.prod.js # packages/react-scripts/package.json
* Allow importing package.json * Remove package.json import from App.js template * fix importing package.json * Rename variable to reflect path is relative to root * Check for both package & package.json in ModuleScopePlugin * Use regex to check relative path to package.json * Strictly enforce package.json extension on scope plugin * Add allowedPaths to ModuleScopePlugin ctor and use it to allow app package.json * Remove package.json import from App.js template * Add package.json to react-scripts/template, show package version and name in the template * Remove import package.json from template * Remove template/package.json and its references in code * Update ModuleScopePlugin.js * Update README.md
* Allow importing package.json * Remove package.json import from App.js template * fix importing package.json * Rename variable to reflect path is relative to root * Check for both package & package.json in ModuleScopePlugin * Use regex to check relative path to package.json * Strictly enforce package.json extension on scope plugin * Add allowedPaths to ModuleScopePlugin ctor and use it to allow app package.json * Remove package.json import from App.js template * Add package.json to react-scripts/template, show package version and name in the template * Remove import package.json from template * Remove template/package.json and its references in code * Update ModuleScopePlugin.js * Update README.md
* Allow importing package.json * Remove package.json import from App.js template * fix importing package.json * Rename variable to reflect path is relative to root * Check for both package & package.json in ModuleScopePlugin * Use regex to check relative path to package.json * Strictly enforce package.json extension on scope plugin * Add allowedPaths to ModuleScopePlugin ctor and use it to allow app package.json * Remove package.json import from App.js template * Add package.json to react-scripts/template, show package version and name in the template * Remove import package.json from template * Remove template/package.json and its references in code * Update ModuleScopePlugin.js * Update README.md
Hi,
Basically, allow to import
package.json
.For example, from
src/App.js
:Only the app own
package.json
is allowed to be imported.It closes #2466